package mylab.io.base.sync;

import com.google.common.eventbus.Subscribe;

import mylab.base.foundation.event.AsyncEventSubscriber;
import mylab.io.base.event.TerminalConnectionChangedEvent;
import mylab.utils.common.guava.LocalCacheService;

/**
 * 所有Couple缓存,为所有终端缓存
 */
public class CoupleCaches extends LocalCacheService<String, CoupleCache> implements AsyncEventSubscriber {
    //默认瞬间最大40K终端数
    static final long MAX_SIZE = 1024 * 10 * 4;

    public CoupleCaches() {
        super(MAX_SIZE);
        AsyncEventSubscriber.super.registerEventListener();
    }

    @Subscribe
    public void onTerminalConnectionChangedEvent(TerminalConnectionChangedEvent event) {
        boolean isConnected = event.getContent();
        if (!isConnected) {
            remove(event.getSource().getId());
        }
    }

}
